$(()=>{
    let addrId = $("#user-addr").val();
    let url = ctx + "/personal/addr";
    $.ajax({
        url,
        method:"get",
        dataType:"json",
        data:{
            id:addrId
        },success(resp){
            if (resp.success){
                //数据回显
                let addr = resp.data;
                $("#receiver").val(addr.receiver);
                $("#receiverPhone").val(addr.receiverPhone);
                $("#province").val(addr.province);
                $("#city").val(addr.city);
                $("#area").val(addr.area);
                $("#street").val(addr.street);
                $("#addrDetail").val(addr.addrDetail)
            }
        }
    });

    //地址改变事件
    $("#user-addr").change(function (){
        let addrId = $(this).val();
        let url = ctx + "/personal/addr";
        $.ajax({
            url,
            method:"get",
            dataType:"json",
            data:{
                id:addrId
            },success(resp){
                if (resp.success){
                    //数据回显
                    let addr = resp.data;
                    $("#receiver").val(addr.receiver);
                    $("#receiverPhone").val(addr.receiverPhone);
                    $("#province").val(addr.province);
                    $("#city").val(addr.city);
                    $("#area").val(addr.area);
                    $("#street").val(addr.street);
                    $("#addrDetail").val(addr.addrDetail)
                }
            }
        });
    });

    $("#submit-order").click(function (){
        let url = ctx + "/order/patch";
        let orderId = $("#current-order").val();//隐藏域数据
        let addrId = $("#user-addr").val();

        //真实地址
        let receiver = $("#receiver").val();
        let receiverPhone = $("#receiverPhone").val();
        let province = $("#province").val();
        let city = $("#city").val();
        let area = $("#area").val();
        let street = $("#street").val();
        let addrDetail = $("#addrDetail").val();
        let payType = $("#payUl>li>label>input[name=payment]:checked").val() +"支付";
        console.log(payType)
        let fullAddr = province + city + area + street + addrDetail + " " +receiver + " " + receiverPhone;
        $.ajax({
            url,
            method:"patch",
            dataType:"json",
            data:{
                userAddrId:addrId,
                receiverAddr:fullAddr,
                state:"已支付",
                id:orderId,
                payType
            },success(resp){
                if (resp.success){
                    layer.msg("支付成功，3秒后跳转到个人中心");
                    setTimeout(()=>{
                        layer.msg("即将跳转到到个人中心");
                        location.href = ctx + "/personal/orders"
                    },3000)
                }
            }
        })

    })
})